home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-03-04 | 10.8 KB | 410 lines | [TEXT/ToyS] |
- -- User setable properties
- property kasAllowAlerts : true -- Set to false to stop any alerts from appearing
- property kasServerAlerts : true -- Set to false to stop warnings about missed servers
- property kasFinder : "Finder" -- name of application that can shutdown and restart
-
- -- Internal/User setable globals
- property gasLinkSet : false -- Has the friend been asked for? - set to true to never ask
- property gasLinkNeed : false
- property gasLinkUser : "CasaVision" -- Our friend on all machines
- property gasLinkPass : "" -- Our friend's password on all machines
-
- -- Internal globals
- property gasOurZone : "" -- Set to zone of gasOurAlias
- property gasOurServer : "" -- Set to server of gasOurAlias
- property gasOurName : "" -- Name of application on remote server
- property gasOurAction : "" -- Set to choice of user (quit, shutdown, restart)
-
- -- Remote Access Stuff
- property kraConnected : "connected"
- property kraProtocol : "ARAP"
- property gasRemote : false -- set internally to true if volume was a RemoteAccess volume
- property gasRemoteCfg : "" -- Set internally to ARA config needed for this access
- property gasRemoteModem : "" -- Set internally to modem for RA connection
- property gasRemoteServer : "" -- Set internally to check if we are already connected to the correct server
- property gasRemoteAlias : false --Set internally to rebuild ARA with alias instead of osax
- property gasRemoteNum : "" -- Set internally to the telephone number of the remote machine
- property gasRemoteUsr : "" -- Set internally to the login user for the remote machine
-
-
- on run
- if (gasOurAction is "") then
- ShowInitAlert()
- else if (gasOurName is not "") then
- RemoteAction(gasOurName, gasOurServer, gasOurZone, gasOurAction)
- else
- PutAwayVol(gasOurVol)
- end if
- end run
-
-
- on open fsObjs
- if option key down of (input state) then
- if the number of items in fsObjs is not 1 then
- ShowInitAlert()
- else if (ShowChoice("You have the option key pressed." & return & return & ¬
- "Do you wish to reinitialize this script with the object you dropped on it?")) then
- SetScriptAlias(item 1 of fsObjs)
- end if
- else if (the number of items of fsObjs is not 1) then
- ShowOpenAlert()
- else
- SetScriptAlias(item 1 of fsObjs)
- end if
- end open
-
-
- on RemoteAction(appName, serverName, zoneName, whatToDo)
- -- Get the user/password
- if not GetFriend(false) then return
-
- if (serverName is not "") then
- talk as user gasLinkUser ¬
- with password gasLinkPass ¬
- on server serverName ¬
- in AppleTalk zone zoneName
-
- -- Mount the remote volume?
- if (gasRemoteAlias) then
- try
- «event ÅkuNResW» gasOurAlias ¬
- given «class USER»:gasLinkUser, «class PASS»:gasLinkPass
- on error
- beep
- end try
- end if
- end if
-
- if serverName is "" then
- set suspect to application appName
- else
- set suspect to application appName ¬
- of machine serverName ¬
- of zone zoneName
- end if
-
- try
- -- Don't wait for a response, assume the aliases are correct?
- if (whatToDo is "Shutdown") then
- tell suspect to «event fndrshut»
- else if (whatToDo is "Restart") then
- tell suspect to «event fndrrest»
- else if (whatToDo is "Quit") then
- tell suspect to quit
- else
- beep 2
- end if
- on error
- if (kasServerAlerts) then
- ShowConnectAlert(appName)
- else
- beep
- end if
- end try
- end RemoteAction
-
-
- on ChooseScriptAlias()
- if ShowChoices("Do you wish to activate this script with a folder/volume or a file?", {"Folder", "File"}) is "File" then
- set myObj to ¬
- choose file with prompt "Choose a server file for this PowerScript RA"
- else
- set myObj to ¬
- choose folder with prompt "Choose a server folder or volume for this PowerScript RA"
- end if
-
- SetScriptAlias(myObj)
- end ChooseScriptAlias
-
-
- on SetScriptAlias(aliasObj)
- -- My Path
- set myPath to (path to me)
-
- -- Grab an alias
- set aInfo to alias info from aliasObj
- set fInfo to basic info for aliasObj
-
- -- Save the info we need
- set gasOurServer to alias server of aInfo
- set gasOurZone to alias zone of aInfo
- set gasOurVol to alias volume of aInfo
- set gasOurName to original name of aInfo
-
- -- Remote info
- set gasRemoteNum to ARA number of aInfo
- set gasRemoteUsr to ARA user of aInfo
- set gasRemotePwd to ARA password of aInfo
-
- -- Set our name to dropped name
- set gasLinkNeed to true
- set gasOurAction to "Quit"
- set newName to (catalog name of fInfo)
-
- if (catalog kind of fInfo) is a folder then
- set gasOurAction to "Put Away"
- set gasLinkNeed to false
- set newName to gasOurVol
- else if (gasOurName is kasFinder) then
- set choice to display dialog ¬
- ("What do you wish to have the " & kasFinder ¬
- & " on " & gasOurServer & ¬
- " do when this script is run?") buttons ¬
- {"Quit", "Restart", "Shutdown"} default button 3
- set gasOurAction to button returned of choice
- if (gasOurAction is not "Quit") then set newName to gasOurServer
- end if
-
- -- Get the user/password
- GetFriend(false)
-
- -- Check ARA connection
- set gasRemote to IsRemoteAccessed()
- if (gasRemote) then SaveRemoteAccess()
-
- -- Set our icon to dropped icon
- set ourIcon to (the icon for aliasObj)
- set the icon of myPath to ourIcon
-
- -- Refresh our new status in the finder
- try
- tell application "Finder" to update myPath -- only works with OS 8
- on error
- beep
- end try
-
- -- Set our new name
- set newName to "≈ " & gasOurAction & " " & newName
- if (length of newName > 31) then set newName to the text from character 1 to 31 of newName
-
- try
- collate myPath renaming it to newName
- on error
- beep
- end try
- end SetScriptAlias
-
-
- on GetFriend(override)
- if (gasOurServer is "") then -- Local?
- set gasLinkSet to true
- set gasLinkUser to kasLinkUserDft
- set gasLinkPass to kasLinkPassDft
- else if (gasLinkNeed) then
- -- Build ARA connection?
- if (gasRemote and not gasRemoteAlias) then
- if not BuildRemoteAccess() then return false
- end if
- -- Get linking friend
- GetOneFriend(override)
- end if
- return true
- end GetFriend
-
-
- on GetOneFriend(override) -- LINKING ONLY VERSION!
- set isLink to true -- Only linking in this script!
- set userMode to "linking"
- set defUser to gasLinkUser
- set defPass to gasLinkPass
- set passButtons to {"Cancel", "OK"}
- set passButton to 2
-
- set usrPwd to KeyChainLookUp(gasOurZone, gasOurServer, isLink)
-
- if (override or usrPwd is {}) then
- set chosen to display dialog ¬
- "Enter the friendly " & userMode & ¬
- " user's name…" default answer defUser ¬
- default button 2 with icon note
-
- if (the button returned of chosen is "OK") then
- set defUser to the text returned of chosen
- else
- return
- end if
-
- set chosen to display dialog ¬
- "Enter the friendly " & userMode & ¬
- " user's password…" buttons passButtons ¬
- default answer defPass default button passButton with icon note
-
- if (the button returned of chosen is not "Cancel") then
- set defPass to the text returned of chosen
- else
- return
- end if
-
- -- Save encrypted user/pass for future access
- KeyChainSave(gasOurZone, gasOurServer, isLink, defUser, defPass, "")
- else
- set defUser to item 1 of usrPwd
- set defPass to item 2 of usrPwd
- end if
-
- set gasLinkSet to true
- set gasLinkUser to defUser
- set gasLinkPass to defPass
- end GetOneFriend
-
-
- on PutAwayVol(volName)
- -- Volume
- try
- tell application "Finder"
- update item named volName
- pause for 2 with seconds timing -- Give some time to the Finder?
- put away item named volName
- end tell
- on error
- beep
- end try
- end PutAwayVol
-
-
- on ShowAccessAlert()
- ShowServerAlert("The remote access connection for the item on " & gasOurServer ¬
- & " in zone " & gasOurZone & " failed to be made.")
- end ShowAccessAlert
-
-
- on ShowConnectAlert(appName)
- ShowServerAlert("Couldn't connect to " & appName & " on " & ¬
- gasOurServer & " in zone " & gasOurZone & return & return & ¬
- "The server may be down or the app may not allow remote events.")
- end ShowConnectAlert
-
-
- on ShowServerAlert(msg)
- set choice to ¬
- display dialog msg buttons {"Reenter Password", "OK"} ¬
- default button 2 with icon stop
-
- if (button returned of choice is not "OK") then GetFriend(true)
- end ShowServerAlert
-
-
- on ShowInitAlert()
- if ShowChoices("This script must first be activated by dropping exactly one item on it." & ¬
- return & return & "Please see the information file that accompanied it.", ¬
- {"Activate", "OK"}) is not "OK" then ¬
- ChooseScriptAlias()
- end ShowInitAlert
-
-
- on ShowOpenAlert()
- ShowAlert("To reconfigure drop exactly one remote item on it.")
- end ShowOpenAlert
-
-
- on ShowAlert(msgStr)
- if (kasAllowAlerts) then ¬
- display dialog msgStr buttons {"Damn!"} ¬
- default button 1 with icon stop
- end ShowAlert
-
-
- on ShowChoices(msgStr, choices)
- set choice to ¬
- display dialog msgStr buttons choices ¬
- default button (number of items of choices) ¬
- with icon stop
- return (button returned of choice)
- end ShowChoices
-
-
- property kasKeyChainPassword : "PowerScript" -- Encrypt stored data with this
- property kasPrefsFileName : "PowerScript Prefs" -- File name in <Preferences>
-
- on KeyChainLookUp(zoneName, serverName, isLinking)
- set prefType to "πSRV"
- if (isLinking) then set prefType to "πLNK"
-
- try
- set myKeyData to load preference of type prefType ¬
- named (zoneName & ":" & serverName) ¬
- in file named kasPrefsFileName
- on error
- return {}
- end try
-
- return (encrypt the data myKeyData ¬
- with password kasKeyChainPassword)
- end KeyChainLookUp
-
-
- on KeyChainSave(zoneName, serverName, isLinking, usr, pwd, ntPwd)
- set myKey to encrypt the data {usr, pwd, ntPwd} ¬
- with password kasKeyChainPassword
-
- set prefType to "πSRV"
- if (isLinking) then set prefType to "πLNK"
-
- save preference myKey of type prefType ¬
- named (zoneName & ":" & serverName) ¬
- in file named kasPrefsFileName
- end KeyChainSave
-
-
- on IsRemoteAccessed()
- try
- set araStats to (RA status)
- on error
- return false
- end try
-
- return ((state of araStats) is kraConnected) ¬
- and ((protocol of araStats) is kraProtocol)
- end IsRemoteAccessed
-
-
- on SaveRemoteAccess()
- set gasRemoteAlias to true
-
- -- Get the ARA config for the alias
- set configs to RA configurations whose numbers are gasRemoteNum ¬
- whose users are gasRemoteUsr
-
- if (the number of items in configs) > 0 then
- set gasRemoteCfg to item 1 of (item 1 of configs) -- The name of the config to use
- set gasRemoteServer to server name of (RA status)
- set gasRemoteModem to «event ÅkuNMdmÇ»
- set gasRemoteAlias to false
- end if
- end SaveRemoteAccess
-
-
- on BuildRemoteAccess()
- set araIsOn to IsRemoteAccessed()
-
- if (araIsOn) then
- -- Connected to correct server?
- if (server name of (RA status)) is gasRemoteServer then
- return true
- else
- RA disconnect
- set araIsOn to IsRemoteAccessed()
- end if
- end if
-
- if (not araIsOn) then
- -- Save current config, set it to ours, connect, set it back
- set saveConfig to RA configuration gasRemoteCfg
- set saveModem to «event ÅkuNMdmÇ» gasRemoteModem
-
- try
- RA connect
- on error
- beep
- end try
-
- RA configuration saveConfig
- «event ÅkuNMdmÇ» saveModem
-
- if (IsRemoteAccessed()) then return true
- end if
-
- ShowAccessAlert()
- return false
- end BuildRemoteAccess
-